/**
 * Collection lists
 * -- community
 * -- community_bulletins
 * -- community_supplements
 */

var Schema = mongoose.Schema;

//==================================================================================
var communityMongoSchema = new Schema({
    communityType: Number,                                               //0,虚拟小区 1,县级小区
    communityName: {type: String, unique: true},                             //小区名称
    communityLogo: String,                                                     //小区logo
    country: {type: Schema.Types.ObjectId, ref: 'masterData_Regions'},  //小区所属国家
    provinceId: {type: Schema.Types.ObjectId, ref: 'masterData_Regions'}, //小区所属省
    cityId: {type: Schema.Types.ObjectId, ref: 'masterData_Regions'},   //小区所属市
    countyId: {type: Schema.Types.ObjectId, ref: 'masterData_Regions'},   //小区所属县
    city: String,     //小区所属市

    subdistrict: String, //行政子区域
    developer: String, //开发商
    propertyType: String, //小区住宅类型
    property: String, //物业
    constructionArea: Number, //小区占地面积(平方米)
    dateBuild: {type: Date},  //小区建造日期
    desc: String, //小区描述
    price: Number, //价格(元/平方)
    greenRate: Number, //绿化率
    rent: Number, //租
    sale: Number, //出售
    pinyin: String, // 拼音
    pinyinShort: String, //拼音缩写

    populationSize: Number,                                                   //人口规模
    communityAddress: String,                                                //小区地址
    communityPostCode: String,                                               //邮政编码
    isValid: {type: Boolean, default: false},
    isInit: {type: Boolean, default: false},    //是否已初始化
    households: Number,
    chatGroupId: String,
    location: {
        longitude: Number,
        latitude: Number
    },
    phoneList: [{
        name: String,
        phoneNo: String,
        address: String,
        user: {type: Schema.Types.ObjectId, ref: 'user'}
    }],
    groups: [
        {type: Schema.Types.ObjectId, ref: 'community_group'}
    ],
    unitSwitch: {type: Boolean, default: false},
    lastModifiedBy: {type: Schema.Types.ObjectId, ref: 'user'},
    dateLastModified: {type: Date, default: Date.now},
    dateEffective :{type: Date},
    versionNo: String
});
mongoose.model('community', communityMongoSchema, 'community');


//==================================================================================
// 小区导入记录
var communityImportSchema = new Schema({
    reason: String,
    province: {type: Schema.Types.ObjectId, ref: 'masterData_Regions'}, //小区所属省
    city: String,     //小区所属市
    county: {type: Schema.Types.ObjectId, ref: 'masterData_Regions'},   //小区所属县
    allRecord:Number,
    failure:Array,
    dateCreated: {type: Date, default: Date.now}
});
mongoose.model('community_import_record', communityImportSchema, 'community_import_record');


//==============================community_bulletins=====================================
var bulletinMongoSchema = new Schema({
    community: [
        {type: Schema.Types.ObjectId, ref: 'community'}
    ],
    title: String,
    imageURL: String,                                     //封面
    isFresh: {type: Boolean, default: false},
    desc: String,
    isValid: {type: Boolean, default: false},
    dateCreated: {type: Date, default: Date.now},
    createdBy: {type: Schema.Types.ObjectId, ref: 'user'}
});
mongoose.model('community_bulletins', bulletinMongoSchema, 'community_bulletins');

//1.5.0
var bannerSchema = new Schema({
    contentId: String,
    openType: Number,
    contentCreatedBy: String,
    contentUrl: String,
    imageURL: String,
    tag: String,                                         //标签
    bgColor: String,                                     //标签颜色
    message: String,
    type: Number,                                       //1,banner;2,新鲜事
    isValid: {type: Boolean, default: true},
    dateLastModified: {type: Date, default: Date.now},
    dateCreated: {type: Date, default: Date.now}
});
mongoose.model('community_banner', bannerSchema, 'community_banner');

var bannerBindSchema = new Schema({
    bannerId: {type: Schema.Types.ObjectId, ref: 'community_banner'},
    community: {type: Schema.Types.ObjectId, ref: 'community'},
    type: Number,                                        //1,banner;2,新鲜事
    dateCreated: {type: Date, default: Date.now},
    displayOrder: {type: Number, default: 0}
});
mongoose.model('community_banner_bind', bannerBindSchema, 'community_banner_bind');

//=============================community_supplements=======================================
var communitySupplementSchema = new Schema({
    community: {type: Schema.Types.ObjectId, ref: 'community'},
    id: String,
    desc: String,
    phone: String,
    address: String,
    dateCreated: {type: Date, default: Date.now},
    status: {type: Boolean},
    createdBy: {type: Schema.Types.ObjectId, ref: 'user'}
});
mongoose.model('community_supplements', communitySupplementSchema, 'community_supplements');

var communityApplicationSchema = new Schema({
    city: {type: Schema.Types.ObjectId, ref: 'masterData_Regions'},
    county: {type: Schema.Types.ObjectId, ref: 'masterData_Regions'},
    user: {type: Schema.Types.ObjectId, ref: 'user'},
    communityName: String,
    address: String,
    note: String,
    status: {type: Number, default: 0},
    type: {type: Number, default: 1},    // 1,自己小区 2,父母小区
    isValid: {type: Boolean, default: true},
    dateCreated: {type: Date, default: Date.now}
});
mongoose.model('community_applications', communityApplicationSchema, 'community_applications');

var communityGroupSchema = new Schema({
    groupName: String,
    dateCreated: {type: Date, default: Date.now}
});
mongoose.model('community_group', communityGroupSchema, 'community_group');

var cardSchema = new Schema({
    contentId: String,
    contentTitle :String,
    openType: Number,
    contentCreatedBy: String,
    contentUrl: String,
    title: String,
    desc: String,
    imageURL: String,
    type: Number,                                       //1,专题
    isValid: {type: Boolean, default: true},
    beginTime:{type:Date},
    endTime:{type:Date},
    province: {type: Schema.Types.ObjectId, ref: 'masterData_Regions'},
    city: {type: Schema.Types.ObjectId, ref: 'masterData_Regions'},
    displayOrder: {type: Number, default: 0},
    dateCreated: {type: Date, default: Date.now}
});
mongoose.model('community_card', cardSchema, 'community_card');


var bannerSchema = new Schema({
    contentId: String,
    openType: Number,
    name: String,                                        //名称
    type: Number,                                        //1:社区邻里问问 2:集市 3:社区随便说说
    openType : Number,                                   //1:活动 2:专题
    imageURL: String,                                    //图片
    url: String,                                         //url
    level: Number,                                       //0:全站 1:省 2:市 3:县区 4:小区
    province: {type: Schema.Types.ObjectId, ref: 'masterData_Regions'},
    city: {type: Schema.Types.ObjectId, ref: 'masterData_Regions'},
    county: {type: Schema.Types.ObjectId, ref: 'masterData_Regions'},
    community: {type: Schema.Types.ObjectId, ref: 'community'},         //所属小区
    beginDate : {type: Date},                            //开始日期
    endDate : {type: Date},                              //结束日期
    bannerOrder : Number,                                //排序
    isValid: {type: Boolean, default: true},
    dateLastModified: {type: Date, default: Date.now},
    dateCreated: {type: Date, default: Date.now}
});
mongoose.model('banner', bannerSchema, 'banner');

var cardSchema = new Schema({
    contentId: String,
    openType: Number,
    title: String,
    desc: String,
    imageURL: String,                                    //图片
    url: String,                                         //url
    level: Number,                                       //0:全站 1:省 2:市 3:县区 4:小区
    province: {type: Schema.Types.ObjectId, ref: 'masterData_Regions'},
    city: {type: Schema.Types.ObjectId, ref: 'masterData_Regions'},
    county: {type: Schema.Types.ObjectId, ref: 'masterData_Regions'},
    beginDate : {type: Date},                            //开始日期
    endDate : {type: Date},                              //结束日期
    cardOrder : Number,                                  //排序
    isValid: {type: Boolean, default: true},
    dateLastModified: {type: Date, default: Date.now},
    dateCreated: {type: Date, default: Date.now}
});
mongoose.model('card', cardSchema, 'card');